package com.kc.web.controller.business;

import com.kc.business.domain.BizPersonalConsignmentGoods;
import com.kc.business.service.IBizPersonalConsignmentGoodsService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import com.kc.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * TODO
 * 寄卖商品
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/10/23
 */
@RestController
@RequestMapping("/business/personalConsignmentGoods")
public class BizPersonalConsignmentGoodsController extends BaseController {
    @Resource
    private IBizPersonalConsignmentGoodsService goodsService;

    /**
     * 获取寄卖商品列表
     */
    @PreAuthorize("@ss.hasPermi('business:personalConsignmentGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizPersonalConsignmentGoods personalConsignmentGoods) {
        startPage();
        List<BizPersonalConsignmentGoods> goodsList = goodsService.getList(personalConsignmentGoods).stream().map(item -> {
            //字符串转景点类型数组
            item.setImgList(StringUtils.split(item.getImgs(), ","));
            return item;
        }).collect(Collectors.toList());
        return getDataTable(goodsList);
    }


    /**
     * 修改寄卖商品
     */
    @PreAuthorize("@ss.hasPermi('business:personalConsignmentGoods:edit')")
    @Log(title = "寄卖商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizPersonalConsignmentGoods personalConsignmentGoods) {
        return toAjax(goodsService.edit(personalConsignmentGoods));
    }

}
